package com.atguigu.jxc.controller;/*
 *@author 尹凯瑞
 *@date 2020/12/5 11:20
 */

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.OverflowService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("overflowListGoods")
public class OverflowController {

    @Autowired
    private OverflowService overflowService;
    //保存报溢单 http://localhost:8080/overflowListGoods/save?overflowNumber=BY1605767033015（报溢单号）
    @RequestMapping("/save")
    public ServiceVO save(OverflowList overflowList, String overflowListGoodsStr, HttpSession session){

        User user = (User)session.getAttribute("currentUser");

        Integer userId = user.getUserId();
        //获取用户trueName
        String trueName = user.getTrueName();
        overflowList.setTrueName(trueName);
        overflowList.setUserId(userId);
        Gson gson = new Gson();
        Type type = new TypeToken<List<OverflowListGoods>>(){}.getType();
        List<OverflowListGoods> overflowListGoodsList = gson.fromJson(overflowListGoodsStr, type);
        return overflowService.saveOverflowList(overflowList,overflowListGoodsList);
    }
    //报溢单查询 http://localhost:8080/overflowListGoods/list
    @RequestMapping("/list")
    public Map<String,Object> list(String sTime, String eTime){
        return overflowService.selectOverflowList(sTime,eTime);
    }
    //报溢单商品查询 http://localhost:8080/overflowListGoods/goodsList
    @RequestMapping("/goodsList")
    public Map<String,Object> goodsList(Integer overflowListId){
        return overflowService.selectOverflowGoodsList(overflowListId);
    }
}
